import { asyncRouters } from '~/router/router'
import router from '~/router'
export const useAddRoutes = (menus: any[]) => {
  //是否有新的路由
  let hasNewRouter = false
  const findAndAddRoutesByMenus = (arr: any[]) => {
    arr.forEach((e) => {
      let item = asyncRouters.find((o) => o.path === e.frontpath)
      if (item && !router.hasRoute(item.path)) {
        router.addRoute('admin', item)
        hasNewRouter = true
      }
      if (e.child && e.child.length > 0) {
        findAndAddRoutesByMenus(e.child)
      }
    })
  }
  findAndAddRoutesByMenus(menus)
  return hasNewRouter
}
